<?php
/* -------------------------------------------------------------------------------------
* 	ID:						$Id: xajax.products_linking.php 11 2013-09-21 11:43:11Z phone.mueller@googlemail.com $
* 	Letzter Stand:			$Revision: 11 $
* 	zuletzt geaendert von:	$Author: siekiera $
* 	Datum:					$Date: 2013-09-21 11:43:11 +0000 (Sat, 21 Sep 2013) $
*
* 	SEO:mercari by Siekiera Media
* 	http://www.seo-mercari.de
*
* 	Copyright (c) since 2011 SEO:mercari
* --------------------------------------------------------------------------------------
* 	based on:
* 	(c) 2000-2001 The Exchange Project  (earlier name of osCommerce)
* 	(c) 2002-2003 osCommerce - www.oscommerce.com
* 	(c) 2003     nextcommerce - www.nextcommerce.org
* 	(c) 2005     xt:Commerce - www.xt-commerce.com
*
* 	Released under the GNU General Public License
* ----------------------------------------------------------------------------------- */

$xajax->registerFunction('linkCategory');
$xajax->registerFunction('delLinkCategory');
$xajax->registerFunction('getLinkedCategories');
$xajax->registerFunction('checkCategory');

function linkCategory() {
	$ajax = new xajaxResponse();
		
	$ajax->append('one_more_link_cat_target', 'innerHTML', generateDropdown());
	
	return $ajax;
}

function checkCategory() {
	$ajax = new xajaxResponse();
	
	$ajax->assign('one_more_link_cat_target', 'innerHTML', draw_pull_down_menu('cPath[]', get_category_tree(0, '', 0), end(explode('_', $_GET['cPath']))));
	if(isset($_GET['pID']) && $_GET['pID'] > 0)	
		$ajax->call('xajax_getLinkedCategories');		
	
	return $ajax;
}

function delLinkCategory($id) {
	$ajax = new xajaxResponse();
	
	$ajax->remove($id);
	
	return $ajax;
}

function getLinkedCategories() {
	global $db;
	$ajax = new xajaxResponse();
	
	$get = $db->db_query("SELECT 
								categories_id
							FROM
								".TABLE_PRODUCTS_TO_CATEGORIES."
							WHERE
								products_id = '".(int)$_GET['pID']."'
							AND
								categories_id != '".end(explode('_', $_GET['cPath']))."'
							AND
								categories_id != '0' ");

	$c = '';
	if($get->_numOfRows) {
		while(!$get->EOF) {
			$c .= generateDropdown($get->fields['categories_id']);
			$get->MoveNext();
		}
		$ajax->append('one_more_link_cat_target', 'innerHTML', $c);
	}
	return $ajax;
}

function generateDropdown($cat_id = '') {
	$select_id = 'sel_'.rand(1, 100000);
	return '<div id="'.$select_id.'"><nobr>'.draw_pull_down_menu('cPath[]', get_category_tree(0, '', 0), $cat_id).' <a id="'.$select_id.'_link" style="font-size:85%" href="javascript:void(0)" onclick="xajax_delLinkCategory(\''.$select_id.'\');return false;">entfernen</a></nobr></div>';
}